import ChatAPI from "@/views/chat/ChatAPI"
import NotifyAPI from "@/views/common/NotifyAPI"

export default {
  namespaced: true,
  state: {
    unreadNotifies: [],

  },
  mutations: {
    addUnreadNotifies(state, notify) {
      //从列表中加入这个
      state.unreadNotifies.unshift(notify)
    },
    setUnreadNotifies(state, notifies) {
      //从列表中加入这个
      state.unreadNotifies = notifies
    }
  },
  actions: {
    queryUnreadNotifies({commit}) {
      return NotifyAPI.queryUnreadNotifies().then(res => {
        commit('setUnreadNotifies', res.data)
      })
    },
    //查询所有未读消息并把所有未读消息改为已读
    queryUnreadNotifiesAndUpdateHasRead({commit}) {
      return NotifyAPI.queryUnreadNotifiesAndUpdateHasRead().then(res => {
        commit('setUnreadNotifies', res.data)
      })
    }
  }
}
